Computers / Programming / Projects / Code Formatter / Type-Id Pair

Type-ID pairs are used to indicate when language transitions and state transitions can start and end as well as when keywords sets are applicable. For example when in a comment keyword highlighting and string highlighting wouldn’t be enabled. They are defined as either startType elements or endType elements depending on where they are used.

c.xml
<startType type="c" id="0" />
56

The Type-ID pair elements defined with attributes that indicate when the transition or set can be considered.

Attribute Description Default Value
type The name of the type “”
id The id of the state. The special * value means always allowed. -1

Code

TypeIdPair.h

h type icon
Type: Header file
Language: C++
TypeIdPair.h

TypeIdPair.cpp

cpp type icon
Type: Code file
Language: C++
TypeIdPair.cpp

The TypeIdPair class is used to store a Type and ID tuple. Type is a string field and stores the abbreviated name of a language while id integer and holds the id of the state. If the definition file has an * for id this is stored as a –1 value. 0 is used to represent the default state of a language. They are also used within the operation of the program to pass the current type and state around.

The IsMatch(TypeIdPair testType) method tests if the passed in TypeIdPair matches this TypeIdPair. This is true if the types match and either the ids match or the id of this TypeIdPair is –1 which indicates all states are allowed.